/**
 *  WaveDevice.h
 *
 *  Copyright (C) 2008  David Andrs <pda@jasnapaka.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#if !defined(AFX_WAVEDEVICE_H__A52F4429_703B_4C7B_AAD5_A6B3CD2CB1D3__INCLUDED_)
#define AFX_WAVEDEVICE_H__A52F4429_703B_4C7B_AAD5_A6B3CD2CB1D3__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class CWaveDevice {
public:
	CWaveDevice();
	virtual ~CWaveDevice();

	void Open();
	void Reset();
	void Pause();
	void Restart();
	void WaitForFinish();
	void WriteAudio(LPSTR data, int size);
	void Close();

	BOOL SetVolume(DWORD volume);
	DWORD GetVolume();

	BOOL IsStereo() { return WCaps.wChannels == 2; }

protected:
	static const int BLOCK_SIZE;
	static const int BLOCK_COUNT;

    HWAVEOUT HWaveOut;					// device handle
    WAVEFORMATEX WFX;
    WAVEOUTCAPS WCaps;

	CRITICAL_SECTION CSWave;
	WAVEHDR *WaveBlocks;
	volatile int WaveFreeBlockCount;
	int WaveCurrentBlock;
	HANDLE HFreeEvent;

	friend void CALLBACK waveOutProc(HWAVEOUT hWaveOut, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2);
};

#endif // !defined(AFX_WAVEDEVICE_H__A52F4429_703B_4C7B_AAD5_A6B3CD2CB1D3__INCLUDED_)
